<extend name="Public/base" />
<block name="content">
<div id="content" style="min-width:800px;">
	<div id="content-header">
		<div id="breadcrumb">
			<a href="{:U('Index/index')}" title="首页" class="tip-bottom"><i
				class="icon-home"></i> 首页</a> <a href="#" class="current">{$meta_title}</a>
		</div>
	</div>
	<div class="container-fluid">
		<br/>

		<div class="search-form fr cf">
			<div class="sleft">
				<span class="control-group">
					<select class="form-control" style="width: 150px;" name="activity_id" id="activity" >
						<option value=0>选择活动</option>
						<volist name="activity_list" id="vo">
							<option value='{$vo.activity_id}'>{$vo.activity_name|strip_tags}</option>
						</volist>
						{$Think.config.ACTIVITY_TTTM}
					</select>
				</span>
				<input type="text" name="mobile_phone" value="{:strip_tags(I('mobile_phone'))}" placeholder="输入手机号查询" maxlength="11" class="search-input"><button class="btn btn-info"  url="{:U('Order/binding')}" id="search_button"><i class="icon-search icon-white"></i></button>
			</div>
		</div>
		
		<div class="row-fluid">
			<div class="span12">
				<div class="widget-box">
					<div class="widget-content">
						<notempty name="_list">
							<table class="table table-bordered table-striped">
								<thead>
									<tr>
										<th nowrap="nowrap">序号</th>
										<th nowrap="nowrap">店铺</th>
										<th nowrap="nowrap">商品</th>
										<th>简介</th>
										<th nowrap="nowrap" >支付金额</th>
										<th>下单时间</th>
										<th nowrap="nowrap">订单</th>
										<th>纸质订单</th>
									</tr>
								</thead>
								<tbody>
									<volist name="_list" id="vo">
										<tr id="order_id_{$vo['order_id']}">
											<td class="taskStatus">{$i}</td>
											<td class="taskStatus" nowrap="nowrap"><font color="red">{$vo.shop_id|getShopName}</font></td>
											<td title="{$vo.goods|htmlspecialchars}">{$vo.goods|htmlspecialchars}</td>
											<td title="{$vo.title|htmlspecialchars}">{$vo.title|htmlspecialchars}</td>
											<td class="taskStatus">{$vo.order_amount}</td>
											<td nowrap="nowrap" class="taskStatus">{$vo.create_time|time_format}</td>
											<td class="taskStatus">{$vo['order_id']}</td>
											<td nowrap="nowrap" class="taskStatus">
												<eq name="vo['order_status']" value="2">
													<button class="btn btn-danger btn-mini bind-order" data-order-id="{$vo['order_id']}" >扫描绑定</button>
												<else/>
													<font color="green">已绑定：{$vo.paper_order}</font>
												</eq>
											</td>
										</tr>
									</volist>
								</tbody>
							</table>
							<div class="control-group" style="text-align:right;">
								共选择：<span id="order_sum">{$_total|default='0'}</span> 单  
							</div>
							<div class="dataTables_paginate fg-buttonset ui-buttonset fg-buttonset-multi ui-buttonset-multi paging_full_numbers" id="DataTables_Table_0_paginate">
								{$_page}
							</div>
						<else/>
							<center>请根据搜索条件进行查询</center>
						</notempty>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>


<!-- 现场退款_获取订单信息 [模板]-->
<script type="text/template" id="tpl_form">
	<div class="one_row">
		<select class="form-control" style="width:150px" name="bind_activity_id" id="bind_activity_id">
		<option value=0>选择活动</option>
			<volist name="activity_list" id="vo">
			<option value='{$vo.activity_id}'>{$vo.activity_name|strip_tags}</option>
			</volist>
			{$Think.config.ACTIVITY_TTTM}
		</select>
	</div>
	<div class="one_row"><input onkeyup="value=value.replace(/[a-zA-z\.]+$/,'')" autofocus placeholder="请输入纸质订单号，回车" id="j-offline-order" /></div>
    <div id="j-info" style="display:none;"></div>
</script>
<!-- /现场退款_获取订单信息 [模板] -->
<!-- 订单信息 [模板]-->
<script type="text/template" id="tpl_order_one">
        <div class="one_row"><span class="name">活动 : </span><a class="value"><%=data.activity_name%></a></div>
        <div class="one_row"><span class="name">商户 : </span><a class="value"><%=data.merchant_name%></a></div>
        <div class="one_row"><span class="name">品类 : </span><a class="value"><%=data.conf_category%></a></div>
        <div class="one_row"><span class="name">店铺 : </span><a class="value"><%=data.shop_name%></a></div>
    </script>
<!-- /订单信息 [模板] -->
<script src="__STATIC__/aui-artDialog-9fd667e/dist/dialog.js"></script>
<link rel="stylesheet" href="__STATIC__/aui-artDialog-9fd667e/css/ui-dialog.css">
  <script src="__JS__/underscore.js"></script>
<script type="text/javascript">
$(function (){
	set_value("activity_id",'{:I('activity_id')}');
	//导航高亮
	highlight_subnav("{:U('Order/binding')}");
});
</script>


<script> 
/*
*@todo  (dialog) 订单绑定2(显示商户信息)
*@param (string) 触发事件对应的选择器名称
*/    
function paperOrderBindingOrder2(select) {
    var URL_BIND      = "{:U('Order/paperOrderBindingOrder')}";
    var d; // 父弹窗(init)

    function _print_hold() {
        var height  = window.screen.height;
        var width   = window.screen.width;
        var url = "{:U('Order/printOnlineOrderVoucher')}";
        var paper_order = $( "#j-offline-order" ).val();
        var bind_activity_id = $('#bind_activity_id').val();
        var query = 'order_id='+order_id+'&paper_order='+paper_order+'&bind_activity_id='+bind_activity_id;
        url = checkUrl(url,query);
        var new_win = window.open(url,'打印页面','height='+height+',width=' + width + ',top=0,left=0,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no');
        return false;
    }

    // 父弹窗
    function _popup_bind() {
        var form_data  = {};
        var form_tpl   = $( "#tpl_form" ).html();
        d = dialog({
            "title": "请输入纸质订单号",
            "content": form_tpl,
            "okValue": "打印",
            "ok": function() {
                _print_hold();
                return false;
            }
        }).showModal();
        $(".ui-dialog-autofocus[i-id=ok]").prop("disabled", "disabled").css("display", "none");
    }

    // 点击触发, 弹出窗口, 获取订单信息
    var order_id = 0;
    $(select).click(function() {
        order_id = $(this).data("orderId");
        _popup_bind();
        
      	//默认活动
    	if("0" != "{:C('JJHH_ACTIVITY_ID')}"){
    		set_value('bind_activity_id', "{:C('JJHH_ACTIVITY_ID')}");
    	}
    });

    // 输入框回车
    $(document).on("keydown", "#j-offline-order", function(e){
        var $ipt = $(this);
        var paper_order_num = $ipt.val();
        if (13 == e.keyCode) {
            if ("" == $ipt.val()) {
                var d_error = dialog({
                    "title": "错误",
                    "content": "订单号不能为空!"
                }).showModal();
                setTimeout(function(){
                    d_error.remove().close();
                    $ipt.focus();
                }, 2000);

            } else {
            	$.ajax({
                    "url": URL_BIND,
                    "type": "POST",
                    "dataType": "json",
                    "data": {
                        "paper_order": paper_order_num ,
                        "order_id" : order_id,
                        "bind_activity_id" : $('#bind_activity_id').val(),
                        "type" : 1,
                    }
                }).done(function(json) {
                    if (1 == json.status) {
                    	_print_hold();
        				return false;                        
                    } else {
                        var d_error = dialog({
                            "title": "错误!",
                            "content": json.info
                        }).showModal();
                        setTimeout(function(){
                            d_error.remove().close();
                            $ipt.select();
                        }, 2000);
                    }
                }); 
            }
        }
    });
}
// 实例化
paperOrderBindingOrder2( ".bind-order" );
</script>
</block>